import { ApiProperty, IntersectionType, PartialType } from '@nestjs/swagger';
import { Type } from 'class-transformer';
import {
  IsBoolean,
  IsNumber,
  IsOptional,
  IsString,
  IsNotEmpty,
  IsArray,
} from 'class-validator';

import { PagerDto } from '~/common/dto/pager.dto';

// 创建分类
export class CreateCategoryDto {
  @ApiProperty({ description: '分类名称' })
  @IsString()
  @IsNotEmpty({ message: '分类名称不能为空' })
  classifyname: string;

  @ApiProperty({ description: '是否展示在前台', default: true })
  @IsBoolean()
  isShow: boolean = true;

  @ApiProperty({ description: '排序值', default: 0 })
  @IsNumber()
  sort: number = 0;
}

// 更新分类
export class UpdateCategoryDto extends PartialType(CreateCategoryDto) {}

class SortItem {
  @ApiProperty({ description: '分类ID' })
  @IsString()
  id: string;

  @ApiProperty({ description: '新的排序值' })
  @IsNumber()
  newSort: number;
}

// 分类排序
export class SortCategoryDto {
  @ApiProperty({ description: '排序数组', type: [SortItem] })
  @IsArray()
  items: SortItem[];
}

//查询分类
export class QueryCategoryDto extends PagerDto {
  @ApiProperty({ description: '分类名称' })
  @IsOptional()
  @IsString()
  classifyname?: string;

  @ApiProperty({ description: '是否展示在前台' })
  @IsOptional()
  @IsBoolean()
  isShow?: boolean;
}
